package com.example.car

import androidx.activity.viewModels
import com.alibaba.android.arouter.facade.annotation.Autowired
import com.alibaba.android.arouter.facade.annotation.Route
import com.alibaba.android.arouter.launcher.ARouter
import com.blankj.utilcode.util.ToastUtils
import com.example.car.databinding.ActivityCarPayBinding
import com.example.car.entity.CarPayParam
import com.example.car.vm.CarPayViewModel
import com.example.common.view.view.BaseMvvmActivity
import dagger.hilt.android.AndroidEntryPoint
import java.text.SimpleDateFormat

@Route(path = "/car/CarPayActivity")
@AndroidEntryPoint
class CarPayActivity : BaseMvvmActivity<ActivityCarPayBinding>() {
    override fun getLayoutId(): Int=R.layout.activity_car_pay
    @Autowired
    @JvmField
    var carCode:String=""

    private val carPayViewModel:CarPayViewModel by  viewModels()
    override fun initView() {
        super.initView()
        ARouter.getInstance().inject(this)
        mDataBinding.carCode.text=carCode
        mDataBinding.carName.text=carCode
        mDataBinding.carTime1.text="月卡到期时间: "+SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(System.currentTimeMillis())
        mDataBinding.carTime2.text=SimpleDateFormat("2026-MM-dd HH:mm:ss").format(System.currentTimeMillis())
        mDataBinding.back.setOnClickListener {
                    finish()
                }

        mDataBinding.btnPayCar.setOnClickListener {
            var carPayParam=CarPayParam(
                 entryTime=SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(System.currentTimeMillis()),
             exitTime=SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(System.currentTimeMillis()),
             id=0,
             parkingDuration= 60,
             parkingSpaceNumber= "A10",
             paymentAmount= 45,
             paymentMethod= 1,
             paymentTime= SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(System.currentTimeMillis()),
             paymentType= 1,
             plateNumber= carCode,
             reservationId= 1
            )
            carPayViewModel.getCarPay(carPayParam)
        }
        carPayViewModel.mSuccessLiveData.observe(this){
            ToastUtils.showLong("缴费成功")
            ARouter.getInstance().build("/car/CarStopActivity").navigation()
        }
        carPayViewModel.mErrorLiveData.observe(this){
            ToastUtils.showLong(it)
        }
    }
}